package com.blrs.service.open.impl;

import java.util.List;
import com.blrs.common.utils.DateUtils;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.domain.OpenCooperation;
import com.blrs.mapper.OpenCooperationMapper;
import com.blrs.service.open.IOpenCooperationService;
import com.blrs.system.mapper.SysUploadFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 开放合作Service业务层处理
 * 
 * @author xiaoyang
 * @date 2024-12-02
 */
@Service
public class OpenCooperationServiceImpl implements IOpenCooperationService
{
    @Autowired
    private OpenCooperationMapper openCooperationMapper;
    @Autowired
    private SysUploadFileMapper sysUploadFileMapper;

    /**
     * 查询开放合作
     * 
     * @param id 开放合作主键
     * @return 开放合作
     */
    @Override
    public OpenCooperation selectOpenCooperationById(Long id)
    {
        OpenCooperation openCooperation = openCooperationMapper.selectOpenCooperationById(id);
        openCooperation.setUploadUrl(sysUploadFileMapper.selectUrlByCode("openCooperation",openCooperation.getUploadFile()));
        openCooperation.setIconUrl( sysUploadFileMapper.selectUrlByCode("openCooperation",openCooperation.getIcon()));
        return openCooperation;
    }

    /**
     * 查询开放合作列表
     * 
     * @param openCooperation 开放合作
     * @return 开放合作
     */
    @Override
    public List<OpenCooperation> selectOpenCooperationList(OpenCooperation openCooperation)
    {
        List<OpenCooperation> openCooperations = openCooperationMapper.selectOpenCooperationList(openCooperation);
        for (OpenCooperation cooperation : openCooperations) {
         cooperation.setIconUrl( sysUploadFileMapper.selectUrlByCode("openCooperation",cooperation.getIcon()));
         cooperation.setUploadUrl(sysUploadFileMapper.selectUrlByCode("openCooperation",cooperation.getUploadFile()));
        }
        return openCooperations;
    }

    /**
     * 新增开放合作
     * 
     * @param openCooperation 开放合作
     * @return 结果
     */
    @Override
    public int insertOpenCooperation(OpenCooperation openCooperation)
    {
        openCooperation.setCreateTime(DateUtils.getNowDate());
        openCooperation.setBelongTo(SecurityUtils.getOrgId().toString());
        return openCooperationMapper.insertOpenCooperation(openCooperation);
    }

    /**
     * 修改开放合作
     * 
     * @param openCooperation 开放合作
     * @return 结果
     */
    @Override
    public int updateOpenCooperation(OpenCooperation openCooperation)
    {
        return openCooperationMapper.updateOpenCooperation(openCooperation);
    }

    /**
     * 批量删除开放合作
     * 
     * @param ids 需要删除的开放合作主键
     * @return 结果
     */
    @Override
    public int deleteOpenCooperationByIds(Long[] ids)
    {

        return openCooperationMapper.deleteOpenCooperationByIds(ids);
    }

    /**
     * 删除开放合作信息
     * 
     * @param id 开放合作主键
     * @return 结果
     */
    @Override
    public int deleteOpenCooperationById(Long id)
    {
        return openCooperationMapper.deleteOpenCooperationById(id);
    }
}
